//
// Created by yangchao on 2022/5/16.
// 101. 对称二叉树: https://leetcode.cn/problems/symmetric-tree/
//

#include "../DataStructure/TreeNode.h"

class IsSymmetric{
public:
    bool isSymmetric(TreeNode* root) {
        if (root == nullptr) return true;
        return dfs(root->left,root->right);
    }
private:
    bool dfs(TreeNode* leftNode, TreeNode* rightNode) {
        if (leftNode == nullptr && rightNode == nullptr) return true;
        if (leftNode == nullptr || rightNode == nullptr) return false;
        if (leftNode->val != rightNode->val) return false;
        return dfs(leftNode->left,rightNode->right) &&
        dfs(leftNode->right,rightNode->left);
    }
};

